// const { json } = require("express");

new Vue({
	el: '#app',
	data: function () {
		return {
			sign_days: [], // 签到日期
			ListHide:false,
			showSchedul:false, //显示新增弹框-用作动画
			showSchedulAll:false, //显示新增弹框

			popupRemoveConfim:false,//删除确认框
			showErrorMsg:false,
			errormsg:'',

			checkStartDay:'',//选中的开始日期
			checkEndDay:'',//选中的结束日期

			loading:true,
			host: window.location.protocol+'//'+window.location.host,
			communityId:'',
			msg:'',
			errorPopup:false,

			bstap:true,//防重复点击
			bstapBtnEdit:true,
			bstapBtn:true,
			removeBstap:true,
			localStorageCommunityId:'',
			nowPageStaffId:'',//'3021060916380000137194',//'3021042719330000163483',


			rangeDate: '',
			rangeShow: false,
			nowToday:'',
			//scrollToDate:'',
			nowCheckDay:'',
			testDay:'',
			requestHeaders:'',


            list:[
                {label:'1月',value:'1',activeShow:false},
                {label:'2月',value:'2',activeShow:false},
                {label:'3月',value:'3',activeShow:false},
                {label:'4月',value:'4',activeShow:false},
                {label:'5月',value:'5',activeShow:false},
                {label:'6月',value:'6',activeShow:false},
                {label:'7月',value:'7',activeShow:false},
                {label:'8月',value:'8',activeShow:false},
                {label:'9月',value:'9',activeShow:false},
                {label:'10月',value:'10',activeShow:false},
                {label:'11月',value:'11',activeShow:false},
                {label:'12月',value:'12',activeShow:false}
            ],
            searchList:[],
            swiper:'',
            initialSlide:0,
            activeYear:'',
            activeYearText:'',
            selectMonth:'',
            showPickerYear:false,
            columnsYear:[],
            minDate: '',
            maxDate: '',
            minYear:'',
            maxYear:'',
            nowMonth:'',
            nowdays:'',
			monthShowDate:'',
			defaultDate:[],
			showEdit:false,
			showDateText:'',
			createDate:{
				mobileMaintenance:'',
				contractStartDate:'',
				contractEndDate:'',
				frequencyMaintenance:'',
				remindMaintenance:''
			},
			editDate:{
				mobileMaintenance:'',
				contractStartDate:'',
				contractEndDate:'',
				frequencyMaintenance:'',
				remindMaintenance:'',
				maintenanceStartDate:'',
				maintenanceEndDate:'',
				maintenancePlanId:'',
				id:'',
			},
			detailInfo:{
			},
			showContractStartDate:false,
			showContractEndDate:false,
			showContractStartDateEdit:false,
			showContractEndDateEdit:false,
			currentStartDate:new Date(),
			currentEndDate:new Date(),
			currentStartDateEdit:new Date(),
			currentEndDateEdit:new Date(),
			equipmentMaintenanceId:'',
			allList:[],
			addSelectDate:true,
			titleDetail:'维保详情',
			checkStartDayEdit:'',
			checkEndDayEdit:'',
			showAdd:true,
			showEditBtn:false,
			lastEndDate:'',//存所有计划最后一个日期
			today:'',
			showClass:false,
		}
	},
	created() {
		this.nowPageStaffId = this.queryUrlParam("userId");
		if(!this.nowPageStaffId){
			this.nowPageStaffId = '';
		}
		this.equipmentMaintenanceId = this.queryUrlParam("equipmentMaintenanceId");
		// var localStorageCommunityId=JSON.parse(localStorage.getItem('hc_currentCommunityInfo'))
		// if(localStorageCommunityId){
		// 	this.communityId=localStorageCommunityId.communityId?localStorageCommunityId.communityId:this.getUrlParam("communityId");
		// }else{
			
		// }
		this.communityId=this.getUrlParam("communityId");
		this.requestHeaders=getRequestHeaders('00',this.communityId);//获取请求头
        // console.log(this.requestHeaders)
		this.setDefaultDate();
	},
	mounted(){
        this.getSwiper(this.initialSlide);		
		// window.addEventListener('scroll', this.scrollToTop,true)
	},
	filters: {
		subStringThree: function (value) {
            if(typeof value=='object' && value.staffName){
				value = value.staffName;
			}
			if (!value  || (typeof value!='string')){
				return ''
			}
			return value.substring(0,3);
		}
	},
	methods: {
		setDefaultDate(){
			let date = new Date();
			var date1=date.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,''); // 2020/01/01
			this.today =date1.split('/')[0] + '-'+this.addZero(date1.split('/')[1]) + '-' + this.addZero(date1.split('/')[2])// // 2020-01-01
			let y = date.getFullYear();
			let m = date.getMonth()<9?'0'+(date.getMonth()+1):date.getMonth()+1;
			let d = date.getDate()<10?'0'+date.getDate():date.getDate();
			this.nowToday = `${y}/${m}/${d}`;
	
			/*
			*设置日历最小日期为当前时间
			*最大日期为当前年+5
			*/
			this.minYear=date.getFullYear();
			this.maxYear=this.minYear+5;
			this.nowMonth=date.getMonth();
			this.nowdays=date.getDate();
			this.minDate=new Date(2021,0, 1)
			// this.minDate=new Date(this.minYear, this.nowMonth, this.nowdays)
			this.maxDate=new Date(this.minYear+5, 11, 31);
			var that=this;
			for (let index =  this.minYear; index <=this.maxYear; index++) {
				that.columnsYear.push({
					text:index+'年',
					value:index
				})  
			}
			
			this.checkStartDay =  this.minYear+'-'+ this.addZero(this.nowMonth) +'-'+this.addZero(this.nowdays);
			var nextDay=that.addDayDate(1,new Date(this.checkStartDay))
			this.checkEndDay = this.timeFormat(nextDay) ;		
			this.getPersonNum();
		},
		formatter(day) {
            if(day.type != 'start' &&  day.type != 'end' && day.type !='start-end'){
				const year = day.date.getFullYear();
				const month = day.date.getMonth() + 1;
				const date = day.date.getDate();

				const dateFullName = year+'/'+this.addZero(month)+'/'+this.addZero(date);
				for (let i = 0; i < this.sign_days.length; i++) {
					// 当前点击的日相同 staffName
					if (dateFullName == this.sign_days[i].day) {
						//console.log('this.sign_days[i].text，',this.sign_days[i].text)
						if(this.sign_days[i].text.length>1){
                            // topInfo text bottomInfo
							day.bottomInfo = this.beautySub(this.sign_days[i].text[0].staffName)+"\r\n"+this.beautySub(this.sign_days[i].text[1].staffName);
							day.className = 'custom__selected-day';
						}else {
							day.bottomInfo = (this.sign_days[i].text[0].staffName).substring(0,3);
						}
						//day.type = 'middle';//selected、start、middle、end、disabled

						if((this.nowToday == dateFullName) && (this.nowToday == this.nowCheckDay)){//className
							day.type = 'selected';
							//day.className = 'custom__selected-day-today';
							//day.className = 'custom__selected-day';
						}else {
							//day.type = 'middle';
							day.className = 'custom__selected-day';
							if (this.nowToday > this.sign_days[i].day){
								day.className = 'custom__selected-passed-day';
							}
						}


						// if(i == (this.sign_days.length-1)){
						// 	day.type = 'single';
						// 	this.testDay = day;
						// 	console.log('lastday',day)
						// }
					}
				}
			}
			return day;
		},
		// scrollToTop(e) {
		// 	var scrollT=e.target.scrollTop
		// 	// console.log(e)
		// 	// console.log(this.monthShowDate)
		// 	if(this.monthShowDate.title=='2021年9月'){
		// 		// console.log('2021年9月',scrollT)
		// 	}
		// },
		beautySub(str,len=3){
			if(str.length>=4){
				str = str.substring(0,3);
			}else if(str.length<len){
				for(var i=0;i<(len-str.length);i++){
					str +="　";
				}
			}
			return str;
		},

		formatRangeDate(date) {
			return `${date.getFullYear()}-${this.addZero(date.getMonth() + 1)}-${this.addZero(date.getDate())}`;
		},
		onRangeConfirm(date) {
			const [start, end] = date;
			this.rangeShow = false;
			this.rangeDate = `${this.formatRangeDate(start)} - ${this.formatRangeDate(end)}`;
			this.checkStartDay = `${this.formatRangeDate(start)}`;
			this.checkEndDay = `${this.formatRangeDate(end)}`;
		},
		
		// 返回 类似 2020/01/01 格式的字符串
		formatDate (year, month, day) {
			month < 10 && (month = '0' + month);
			day < 10 && (day = '0' + day);
			var data = year + '/' + month + '/' + day;

			return data;
		},

		
		//获取两日期之间日期列表函数
		addZero(n){
		 	return	n=n<10?'0'+n:n;
		},
		removeZero(n){
			return n<10?Number(n):n
	   },


		/*查询所有维保计划*/
		getPersonNum(clickDay){
			var that=this;
			var today=new Date().toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');
			today =today.split('/')[0] + '-'+this.addZero(today.split('/')[1]) + '-' + this.addZero(today.split('/')[2])
			var url=this.host+'/app/maintenancePlanDetail.listMaintenancePlanDetail';
			// var url=this.host+'/app/repair.listRecentlyDaysRepairSchedulingList';
			var params={
				"communityId":that.communityId,
				"equipmentMaintenanceId":that.equipmentMaintenanceId,
				"maintenancePlanId":'',
				"page":'',
				"row":''
			}
		
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					// console.log(res);
					if(res.code=='0000'){
						setTimeout(function(){
							that.loading=false;
						},800)
					
						if(res.data.length>0){
							that.showAdd=false;
							that.showEditBtn=true;
							var list=res.data;
							var listLength=list.length;
							that.lastEndDate=list[listLength-1].maintenanceEndDate;
							console.log('数据最后一条结束日期：'+that.lastEndDate)
							// console.log('15天接口',list)
							var listArr=[];
							
							list.forEach(function(item, index) {
								var day = item.maintenanceDate.replace('-','/');
								day = day.replace('-','/');	
								listArr.push({
									day: day,
									dayType:item.maintenanceDate,
									text:[
										{staffName:item.nameFixedAsset?item.nameFixedAsset:''},//固定资产名称
										{staffName:item.receiverEquipment?item.receiverEquipment:''}//设备领用人
									],
									orgName:'',	
								})
								that.allList.push({
									date:item.maintenanceDate
								})
							})	
							// that.defaultDate=null;
							// var nextDay=that.addDayDate(1,new Date(listArr[0].dayType))
							// that.defaultDate=[new Date(listArr[0].dayType),nextDay];
							that.searchMonth(that.minYear,that.nowMonth);
							that.sign_days = listArr;
							that.$refs.calendarDate.scrollToDate(new Date(today))
							// console.log(listArr[0].dayType)
							that.showDateText=listArr[0].dayType;
							that.getTodayPlace([],listArr[0].dayType)
					        
						}else{//无数据的展示
							var listArr=[];
							that.showAdd=true;
							that.showEditBtn=false;
							listArr.push({
								day: '',
								text:'',
								orgName:''
							})
							that.searchMonth(that.minYear,that.nowMonth);
							that.sign_days = listArr;
						}
					}else{
						that.showAdd=false;
						that.showEditBtn=false;
						that.loading=false;
						that.errorPopup=true;
						that.msg=res.msg;
						that.searchMonth(that.minYear,that.nowMonth);
					}
				},
				error:function(res){
					that.showAdd=false;
					that.showEditBtn=false;
					that.loading=false;
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
		},
		addDayDate(dayNumber, date){
			date = date ? date : new Date();
			var ms = dayNumber * (1000 * 60 * 60 * 24)
			var newDate = new Date(date.getTime() + ms);
			return newDate;
		},
		fm(date){
			var date1=date.toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,''); // 2020/01/01
			return date1
		},
		scrollTOview(id){
			setTimeout(function(){
				$('#clickId').attr('href','#'+id).click();
				document.getElementById(id).scrollIntoView()
			},100)
		},
		/*查询某天明细*/
		getTodayPlace(date,autoShowDetail){
			let checkType = 1;
			var maintenanceDate='';
			var EditTitleArray=[];
			EditTitleArray=date;
			var that = this;
			var dateStart='';
			var dataEnd=''
			if(typeof date=='object' && date[0]){
				dateStart=date[0];
			}
			if(typeof date=='object' && date[1]){
				dataEnd=date[1];
			}
			// console.log('date==',date,autoShowDetail,dateStart)
			if(autoShowDetail){
				maintenanceDate=autoShowDetail
			}else{
				if(typeof date=='object' && date[1]){
					date = date[1];
				}else if(typeof date=='object' && date[0]){
					date = date[0];
					checkType=2;
				}else {
					checkType=2;
				}
				if(date[0]){
					date[0].type = 'selected';
				}

				that.personList = [];
				var d=new Date(date);
				var year=d.getFullYear();
				var month=d.getMonth()+1;
				var days=d.getDate();
				if(checkType == 2){
					this.checkStartDay = year+'-'+ this.addZero(month)+'-'+this.addZero(days);
					this.checkEndDay = '';
				}
				this.nowCheckDay = year+'/'+ month+'/'+days;
				if(month <10){
					month = '0'+month;
				}
				if(days <10){
					days = '0'+days;
				}
				var daytime = year+'-'+ month+'-'+days;
				maintenanceDate=daytime
			}
			this.showDateText=maintenanceDate;
			if(this.showEditBtn == true  && dataEnd){//修改的情况下，点击当天不去请求数据
				if(EditTitleArray[0] && EditTitleArray[1] ){//显示维保计划时间
					this.checkStartDayEdit=this.timeFormat(EditTitleArray[0]);
					this.checkEndDayEdit=this.timeFormat(EditTitleArray[1]);
					this.ListHide=true;
					if(this.showEdit==false){
						this.titleDetail=this.timeFormat(EditTitleArray[0])+'~'+this.timeFormat(EditTitleArray[1])+' 维保详情';
					}else{
						this.titleDetail=this.timeFormat(EditTitleArray[0])+'~'+this.timeFormat(EditTitleArray[1])+' 修改维保';
					}
					
				}
				return;
			}
			if(dateStart){
				this.showClass=true;
				// console.log(this.diffentTime(this.timeFormat(dateStart),this.lastEndDate))
				// console.log(this.diffentTime(this.timeFormat(dateStart),this.today))
				// console.log(this.timeFormat(dateStart),this.today,this.lastEndDate)
				if(this.diffentTime(this.timeFormat(dateStart),this.today)){//点击选中的开始时间和当前时间对比 false表示已经过去的日期 修改新增按钮隐藏 只能查看详情
					if(this.lastEndDate!=''){
						if(this.diffentTime(this.timeFormat(dateStart),this.lastEndDate)){//点击选中的开始时间和计划列表数据最后一条结束时间对比 false表示不能新增
							this.showEditBtn=false;
							this.showAdd=true;
						}else{
							this.showEditBtn=true;
							this.showAdd=false;
						}
					}
				}else{
					this.showClass=false;
					this.showEditBtn=false;
					this.showAdd=false;

				}
			}

			var url=this.host+'/app/maintenancePlanDetail.listMaintenancePlanDetail';
			var params={
				"communityId":that.communityId,
				"equipmentMaintenanceId":that.equipmentMaintenanceId,
				"maintenancePlanId":'',
				"page":'1',
				"row":'1',
				"selectedDate":maintenanceDate
			}
		
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					console.log('查询某天接口',res);
					if(res.code=='0000'){
						that.loading=false;
						if(res.data.length>0){
							that.ListHide=true;
							that.detailInfo=res.data[0];
							that.checkStartDayEdit=that.detailInfo.maintenanceStartDate;
							that.checkEndDayEdit=that.detailInfo.maintenanceEndDate;
							if(that.showEdit==false){
								that.titleDetail=that.detailInfo.maintenanceStartDate+'~'+that.detailInfo.maintenanceEndDate+' 维保详情';
							}else{
								that.titleDetail=that.detailInfo.maintenanceStartDate+'~'+that.detailInfo.maintenanceEndDate+' 修改维保';
							}
							// console.log(that.checkStartDayEdit,that.checkEndDayEdit)
							that.$refs.calendarDate.scrollToDate(new Date(maintenanceDate))
						}else{
                            that.ListHide=false;
						}
					}else{
						that.loading=false;
						that.errorPopup=true;
						that.msg=res.msg;
					}
				},
				error:function(res){
					that.loading=false;
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
		},
		//添加新增弹框
		addSchedul(){
			var that=this;
			that.showSchedulAll=true;
			this.currentStartDate=new Date();
			this.currentEndDate=new Date();
			this.createDate.mobileMaintenance='';
			this.createDate.contractStartDate='';
			this.createDate.contractEndDate='';
			this.createDate.frequencyMaintenance='';
			this.createDate.remindMaintenance='';
			setTimeout(function(){
				that.showSchedul=true;
			},50)
		},
		//关闭添加新增弹框
		closePopup(){
			var that=this;
			this.showSchedul=false;
			setTimeout(function(){
				that.showSchedulAll=false;
			},350)
		},
		//确认删除
		removeConfim(){
			let that=this;
			//调删除接口
				let url=this.host+'/app/repair.deleteRepairSchedulingByManager';
				let params={
					"communityId":this.communityId,
				}

				if(that.removeBstap==false){
					return;
				}
				that.removeBstap=false
				$.ajax({
					url : url,
					type: 'POST',
					dataType:'json',
					contentType: 'text/plain',
					headers:that.requestHeaders,
					data: JSON.stringify(params),
					success : function (res){
						that.removeBstap=true
						if(res.code=='200'){
							that.showErrorMsg=true;
							that.errormsg='删除成功！';
							setTimeout(function(){
								that.showErrorMsg=false;
							},1500)
							that.popupRemoveConfim=false;
							// console.log('删除前day=',day)
							that.getPersonNum(day);
							return;	
						}else{
							that.errorPopup=true;
							that.msg=res.msg
						}
					},
					error:function(res){
						that.removeBstap=true
						that.errorPopup=true;
						that.msg=res.responseText?res.responseText:'请求超时'
					}
				})
			
		},
		diffentTime(start,end){
			start=new Date(start);
			end=new Date(end);
			if (start >= end) {
				return true;
			}else{
				return false;
			}
		},
		//新建维保提交接口
		submit_add(){
			let that=this;
			if(that.bstapBtn==false){
				return;
			}
		
			if(that.createDate.mobileMaintenance==''){
				that.showErrorMsg=true;
				that.errormsg='维保人手机号不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}

			// else if(that.createDate.contractStartDate==''){
			// 	that.showErrorMsg=true;
			// 	that.errormsg='请选择合同开始日期';
			// 	setTimeout(function(){
			// 		that.showErrorMsg=false;
			// 	},1500)
			// 	return
			// }else if(that.createDate.contractEndDate==''){
			// 	that.showErrorMsg=true;
			// 	that.errormsg='请选择合同结束日期';
			// 	setTimeout(function(){
			// 		that.showErrorMsg=false;
			// 	},1500)
			// 	return
			// }
			else if(that.createDate.frequencyMaintenance==''){
				that.showErrorMsg=true;
				that.errormsg='维保频率不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}else if(that.createDate.remindMaintenance==''){
				that.showErrorMsg=true;
				that.errormsg='提前XX日提醒不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}

			var regPhone = /^1[3456789]{1}\d{9}$/
			if(that.createDate.mobileMaintenance !='' && !regPhone.test(that.createDate.mobileMaintenance)){
				that.showErrorMsg=true;
				that.errormsg='请输入正确的手机格式';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return;
			}
			if(that.createDate.contractStartDate!='' && that.createDate.contractEndDate!=''){
				if(that.diffentTime(that.createDate.contractStartDate,that.createDate.contractEndDate)){
					that.showErrorMsg=true;
					that.errormsg='合同结束日期需大于合同开始日期';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)
					return
				}
			}
		   
			let params={
				"communityId":that.communityId,
				"maintenanceStartDate":that.checkStartDay,
				"maintenanceEndDate":that.checkEndDay,
				"equipmentMaintenanceId":that.equipmentMaintenanceId,
				"mobileMaintenance":that.createDate.mobileMaintenance,
				"contractStartDate":that.createDate.contractStartDate,
				"contractEndDate":that.createDate.contractEndDate,
				"frequencyMaintenance":that.createDate.frequencyMaintenance,
			    "remindMaintenance":that.createDate.remindMaintenance
			}
			let url=that.host+'/app/maintenancePlan.addMaintenancePlanInfo'; 
			that.bstapBtn=false;
			$.ajax({
				url : url,
				type: 'POST',
				dataType:'json',
				contentType: 'text/plain',
				headers:that.requestHeaders,
				data: JSON.stringify(params),
				success : function (res){
					console.log('新增维保提交接口',res);
					that.bstapBtn=true;
					if(res.code=='0000'){
						that.showErrorMsg=true;
						that.errormsg='新增维保成功！';
						var today=that.minYear+'-'+Number(that.nowMonth+1)+'-'+that.nowdays;
						var nextDay=that.addDayDate(1,new Date(today))
						that.defaultDate=null;
						that.defaultDate=[new Date(today),new Date(nextDay)];
						that.$refs.calendarDate.scrollToDate(new Date(today))
						that.setDefaultDate();
						setTimeout(function(){
							that.showErrorMsg=false;
						},1500)
						that.showSchedul=false;
						setTimeout(function(){
							that.showSchedulAll=false;
						},350)
						return;	
					}else{
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.bstapBtn=true;
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
		},

		//获取小数点前面的数字
		getInteger(num){
			var val=num.toString();
			if(val.indexOf('.')==-1){
				return val;
			}else{
				return val.substring(0,val.indexOf('.'))
			}
		},
		//时分比较
		timeComparison(start,end){
			//分割开始时间的时
			let kaiShi = start.split(":")[0];
			//分割开始时间的分
			let kaiFen = start.split(":")[1];
			//分割结束时间的时
			let jieShi = end.split(":")[0];
			//分割结束时间的分
			let jieFen = end.split(":")[1];
			//判断两者的时
			if(kaiShi < jieShi){
				return false;
			}else if(kaiShi == jieShi){
				//如果等于的话就判断两者的分
				if(kaiFen < jieFen){
					return false;
				}else{
					return true;
				}
			}else{
				return true;
			}
		},
		getUrlParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
			var r = window.location.search.substr(1).match(reg); //匹配目标参数
			if (r != null) return unescape(r[2]);
			return null; //返回参数值
	  
		},
		queryUrlParam(name) {
			var reg = new RegExp("(^|\&\?)" + name + "=([^&]*)(&|$)", "i");
			var r = decodeURI(window.location.href.substr(1)).match(reg);
			if (r != null) {
				return unescape(r[2]);
			} else {
				return null;
			}

		},

        getListMonth(date){
            if(date){
                var m=new Date(date).getMonth()+1;
            }else{
                var m=new Date().getMonth()+1;
            }
            return m;
            // var r = new Date(date).toLocaleDateString().replace(/(年|月)/g, '/').replace('日', '').replace(/[^\d-/]/g,'');2021/7/5
        },
        getListYear(date){
            var y=new Date(date).getFullYear();
            return y;
        },
        searchMonth(year,monthSwiper){
			console.log(year,monthSwiper)
            var that=this;
            if(year){
                that.activeYear=year;
            }else{
                that.activeYear=new Date().getFullYear();
            }
            that.activeYearText=that.activeYear+'年';
            that.selectMonth=monthSwiper+1;
			for (var index = 0; index < that.allList.length; index++) {//过滤-当前显示的某一年的数据
				const element = that.allList[index];
				var year=that.getListYear(element.date);
				var month=that.getListMonth(element.date);
				if(that.activeYear == year){
					that.searchList.push(element);
				}   
				for (let j = 0; j < that.list.length; j++) {
					const ele = that.list[j];
					if(that.activeYear == year && month==ele.value){
						that.$set(ele,'activeShow',true)    
					} 
				} 
			}
	
			that.$nextTick(function(){
				that.getSwiper(monthSwiper);//定位到当前月
			})
		},
		//月份swiper展示
		getSwiper(initialSlide){
			// console.log(initialSlide)
			this.swiper = new Swiper('.swiper-container', {
				slidesPerView: 4,
				spaceBetween: 10,
				freeMode :true,//是否滑动
				paginationClickable: true,
				initialSlide :initialSlide,
				observer:true,//修改swiper自己或子元素时，自动初始化swiper 
				observeParents:false,//修改swiper的父元素时，自动初始化swiper
			});
		},
        //月份点击切换
        typeMonthChange(item){
            this.selectMonth=item.value;
            var today=this.activeYear+'-'+this.selectMonth+'-1'
            this.$refs.calendarDate.scrollToDate(new Date(today))
        },
        //年份切换确定
        onConfirmYear(value) {
            var that=this;
            this.activeYear = value.value;
            this.activeYearText = value.text;
            this.showPickerYear = false;
            this.searchList=[];
            for (let j = 0; j < this.list.length; j++) {
                const ele = that.list[j];
                that.$set(ele,'activeShow',false)         
            }  
			var today;
			this.swiper.destroy(false);
			this.swiper.init();
            if(this.activeYear==this.minYear){
                today=this.minYear+'-'+Number(this.nowMonth+1)+'-'+this.nowdays
                this.searchMonth(this.activeYear,this.nowMonth);
            }else{
                today=this.activeYear+'-1-1';
                this.searchMonth(this.activeYear,0);
            }
            this.$refs.calendarDate.scrollToDate(new Date(today))
        },
        monthShow(date){
			// this.monthShowDate=date
			// // console.log(date)
			// var d=new Date(date.date);
			// var y=d.getFullYear();
			// var m=d.getMonth();
			// this.activeYear = y;
            // this.activeYearText =y+'年';
			// // console.log(y,m)
			// this.searchMonth(this.activeYear,m);
        },
				
		//编辑
		editSelect(){
			this.showEdit=true;
			this.addSelectDate=false;//区分日期选择是修改还是新增
			this.editDate.maintenanceStartDate=this.detailInfo.maintenanceStartDate;
			this.editDate.maintenanceEndDate=this.detailInfo.maintenanceEndDate;
			this.editDate.mobileMaintenance=this.detailInfo.mobileMaintenance;
			this.editDate.contractStartDate=this.detailInfo.contractStartDate;
			this.editDate.contractEndDate=this.detailInfo.contractEndDate;
			this.editDate.frequencyMaintenance=this.detailInfo.frequencyMaintenance;
			this.editDate.remindMaintenance=this.detailInfo.remindMaintenance;
			this.editDate.id=this.detailInfo.id;
			this.editDate.maintenancePlanId=this.detailInfo.maintenancePlanId;
			this.titleDetail=this.editDate.maintenanceStartDate+'~'+this.editDate.maintenanceEndDate+' 修改维保';
			this.currentStartDate=new Date(this.editDate.contractStartDate);
			this.currentEndDate=new Date(this.editDate.contractEndDate);
			this.defaultDate=null;
		    this.defaultDate=[new Date(this.editDate.maintenanceStartDate),new Date(this.editDate.maintenanceEndDate)]
		   
		},
		//保存修改
		saveEdit(){
			var that=this;
			vant.Dialog.confirm({
				title: '温馨提示',
				message: '本次修改将删除上次数据，是否确认修改？',
				confirmButtonColor:'#0681FC'
			})
			.then(() => {
				that.showEdit=false;
				that.titleDetail=that.detailInfo.maintenanceStartDate+'~'+that.detailInfo.maintenanceEndDate+' 维保详情';
				that.addSelectDate=true;//区分日期选择是修改还是新增	
				that.saveEditRequire();
			})
			.catch(() => {
				// on cancel
			});
			
		},
        //取消修改
		cancelEdit(){
			this.showEdit=false;
			this.addSelectDate=false;
			this.defaultDate=null;
			this.titleDetail=this.detailInfo.maintenanceStartDate+'~'+this.detailInfo.maintenanceEndDate+' 维保详情';
			var nextDay=this.addDayDate(1,new Date(this.detailInfo.maintenanceStartDate))
			this.defaultDate=[new Date(this.detailInfo.maintenanceStartDate),nextDay]
			// console.log(nextDay,this.showDateText)
		},
		//修改维保提交接口
		saveEditRequire(){
			let that=this;
			if(that.bstapBtnEdit==false){
				return;
			}
		
			if(that.editDate.mobileMaintenance==''){
				that.showErrorMsg=true;
				that.errormsg='维保人手机号不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}
			/*
			else if(that.editDate.contractStartDate==''){
				that.showErrorMsg=true;
				that.errormsg='请选择合同开始日期';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}else if(that.editDate.contractEndDate==''){
				that.showErrorMsg=true;
				that.errormsg='请选择合同结束日期';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}*/
			else if(that.editDate.frequencyMaintenance==''){
				that.showErrorMsg=true;
				that.errormsg='维保频率不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}else if(that.editDate.remindMaintenance==''){
				that.showErrorMsg=true;
				that.errormsg='提前XX日提醒不能为空';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return
			}

			var regPhone = /^1[3456789]{1}\d{9}$/
			if(that.editDate.mobileMaintenance !='' && !regPhone.test(that.editDate.mobileMaintenance)){
				that.showErrorMsg=true;
				that.errormsg='请输入正确的手机格式';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				return;
			}
			if(that.editDate.contractStartDate!='' && that.editDate.contractEndDate!=''){
				if(that.diffentTime(that.editDate.contractStartDate,that.editDate.contractEndDate)){
					that.showErrorMsg=true;
					that.errormsg='合同结束日期需大于合同开始日期';
					setTimeout(function(){
						that.showErrorMsg=false;
					},1500)
					return
				}
			}
			let params={
				"communityId":that.communityId,
				"maintenanceStartDate":that.checkStartDayEdit,
				"maintenanceEndDate":that.checkEndDayEdit,
				"equipmentMaintenanceId":that.equipmentMaintenanceId,
				"mobileMaintenance":that.editDate.mobileMaintenance,
				"contractStartDate":that.editDate.contractStartDate,
				"contractEndDate":that.editDate.contractEndDate,
				"frequencyMaintenance":that.editDate.frequencyMaintenance,
				"remindMaintenance":that.editDate.remindMaintenance,
				"maintenancePlanId":that.editDate.maintenancePlanId,
				"id":that.editDate.id,
			}
			console.log(params)
			let url=that.host+'/app/maintenancePlan.updateMaintenancePlanInfo'; 
			that.bstapBtnEdit=false;
			$.ajax({
				url : url,
				type: 'POST',
				dataType:'json',
				contentType: 'text/plain',
				headers:that.requestHeaders,
				data: JSON.stringify(params),
				success : function (res){
					console.log('修改维保提交接口',res);
					that.bstapBtnEdit=true;
					if(res.code=='0000'){
						that.showErrorMsg=true;
						that.errormsg='修改维保成功！';	
						var today=that.minYear+'-'+Number(that.nowMonth+1)+'-'+that.nowdays;
						var nextDay=that.addDayDate(1,new Date(today))
						that.defaultDate=null;
						that.defaultDate=[new Date(today),new Date(nextDay)];
						that.$refs.calendarDate.scrollToDate(new Date(today))
						that.setDefaultDate();
						setTimeout(function(){
							that.showErrorMsg=false;
						},1500)
						that.showSchedul=false;
						setTimeout(function(){
							that.showSchedulAll=false;
						},350)
						return;	
					}else{
						that.errorPopup=true;
						that.msg=res.msg
					}
				},
				error:function(res){
					that.bstapBtnEdit=true;
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
				}
			})
		},


		//合同开始日期
		clickContractStartDate(){
            this.showContractStartDate=true
		},
		confirmContractStartDate(value){
			this.createDate.contractStartDate = this.timeFormat(value);
            this.showContractStartDate = false;
        },
		//合同结束日期
		clickContractEndDate(){
            this.showContractEndDate=true
		},
		confirmContractEndDate(value){
			this.createDate.contractEndDate = this.timeFormat(value);
            this.showContractEndDate = false;
        },
        //修改
		//合同开始日期
		clickContractStartDateEdit(){
            this.showContractStartDateEdit=true
		},
		confirmContractStartDateEdit(value){	
			this.editDate.contractStartDate = this.timeFormat(value);
            this.showContractStartDateEdit = false;
        },

		//合同结束日期
		clickContractEndDateEdit(){
            this.showContractEndDateEdit=true
		},
		confirmContractEndDateEdit(value){
			this.editDate.contractEndDate = this.timeFormat(value);
            this.showContractEndDateEdit = false;
        },
        timeFormat(time) { // 时间格式化 2019-09-08
             let year = time.getFullYear();
             let month = time.getMonth() + 1;
             let day = time.getDate();
             return year + '-' + this.addZero(month) + '-' + this.addZero(day)
        },
		formatteType(type, val) {
			if (type === 'year') {
			  return val + '年';
			}
			if (type === 'month') {
			  return val + '月';
			}
			if (type === 'day') {
			  return val + '日';
			}
			return val;
		},
	}
});